import { placeOnMap } from './pos2';
import { placeOnMap as placeOnMap3 } from './pos3';
import { fromTemplate, withCustomGlyph } from './builder';

export const generateMap = (world, template, floor, mapping) => {
  const glyphs = template.split('\n').filter(x => x !== '');
  glyphs.forEach((line, y) => {
    line.split('').forEach((glyph, x) => {
      const f = fromTemplate(world, floor);
      placeOnMap(world, f, x, y);
      if (mapping[glyph]) {
        const e = fromTemplate(world, mapping[glyph]);
        placeOnMap(world, e, x, y);
      }
    });
  });
};

export const generateMap3 = (world, template: string, floor, x0, y0, z0, mapping) => {
  const glyphs = template.split('\n').filter((c) => c !== '');
  const z = z0;
  glyphs.forEach((line, dy) => {
    const y = y0+dy;
    line.split('').forEach((glyph, dx) => {
      const x = x0+dx;
      if (floor !== undefined) {
        const f = fromTemplate(world, floor);
        placeOnMap3(world, f, x, y, z);
      }
      if (mapping[glyph]) {
        const e = fromTemplate(world, mapping[glyph]);
        placeOnMap3(world, e, x, y, z);
      }
    });
  });
};
